package com.fast.linkbeanadmin.utils.response;

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author ruan cai yuan
 * @version 1.0
 * @fileName com.fast.linkbeanadmin.utils.response.ResponseUtil
 * @description: 响应工具类
 * @since 2024/7/21 下午5:55
 */
@Slf4j
public class ResponseUtil {
    public static void responseData(HttpServletResponse response, Object o, String type) {
        response.setCharacterEncoding("UTF-8");
        response.setContentType(type);
        try (PrintWriter writer = response.getWriter()) {
            writer.println(JSONUtil.toJsonStr(o));
            writer.flush();
        } catch (IOException e) {
            log.error("数据写回前端异常！！！");
        }
    }
}

